package vim.meet.cglib;


import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class ReadWriteIntercept implements MethodInterceptor {

    @Override
    public Object intercept(Object target, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        Object result = null;
        System.out.println(method.getName());
        String name = method.getName();
        if(name.equals("readSomething")){
            result = proxy.invokeSuper(target, args);
//            System.out.println("original result:" + result);
            result = "replaced";
        }else if(name.equals("writeSomething")){
//          assert args.length == 1
            System.out.println("proxy arg:xxxxx");
          args[0] = "xxxxx";
          result = proxy.invokeSuper(target, args);
//          assert result == null
//          System.out.println(result);
        }
        return result;
    }

}
